package com.example.administrator.xiaobo.adapter.show_adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.xiaobo.R;
import com.example.administrator.xiaobo.bean.show_9_itemBean;

import java.util.LinkedList;

/**
 * Created by Administrator on 2017/2/9.
 * viewType = 9
 */

public class ShowAdapter4 extends RecyclerView.Adapter<ShowAdapter4.MyViewHolder> {
    private Context context;
    private LinkedList<show_9_itemBean> data;

    public ShowAdapter4(Context context, LinkedList<show_9_itemBean> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_show0202,null);

        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        String times = data.get(position).times;
        String s = times.substring(0,3);
        if (("00:").equals(s)) {
            s = "";
        }else if(("01:").equals(s)){
            s = "1:";
        }else if(("02:").equals(s)){
            s = "2:";
        }
        holder.time.setText(s+times.substring(3));
        holder.title.setText(data.get(position).title);
        holder.name.setText(data.get(position).name);
        holder.sourceName.setText(data.get(position).sourcename);
        holder.num.setText(data.get(position).viewnum+"");
        Glide.with(context).load(data.get(position).level1).placeholder(R.drawable.app_empty_icon).
                error(R.drawable.app_empty_icon).into(holder.imageView);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        ImageView imageView;
        TextView time;
        TextView title;
        TextView name;
        TextView sourceName;
        TextView num;
        public MyViewHolder(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.imageView_show0202);
            time = (TextView) itemView.findViewById(R.id.time_show0202);
            title = (TextView) itemView.findViewById(R.id.name_up);
            name = (TextView) itemView.findViewById(R.id.name_bellow2);
            sourceName = (TextView) itemView.findViewById(R.id.name_bellow);
            num = (TextView) itemView.findViewById(R.id.movie_people);
        }
    }
}
